﻿<UserControl x:Class="ScrumFactory.Team.ProjectTeam"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                                       
             xmlns:props="clr-namespace:ScrumFactory.Team.Properties"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             
             xmlns:SF_Comp="clr-namespace:ScrumFactory.Composition;assembly=ScrumFactory.Composition"                             
             xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"
             
             x:Name="thisView"
             
             mc:Ignorable="d" 
             
             
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.InputBindings>
        <KeyBinding Key="Enter" Command="{Binding AddNewMemberCommand}"/>            
    </UserControl.InputBindings>

    <UserControl.Resources>
        
  
    </UserControl.Resources>

    <SF_Helpers:PanelLayout Title="{Binding PanelName}" >

        <!-- TOOLBAR -->
        <SF_Helpers:PanelLayout.Toolbar>

            <ToolBar>

                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    
                    <Border Grid.Column="0">
                        <StackPanel Orientation="Horizontal">
                            <ComboBox                                                                                            
                                VerticalAlignment="Center" Margin="3,0,0,0"
                            
                                SelectedValue="{Binding SearchMemberAvailability}"                                
                                Style="{StaticResource MemberAvailabilityComboBox}"/>
                            <SF_Helpers:FilteredComboBox            
                            HorizontalAlignment="Left" VerticalAlignment="Center" Width="300" 
                            AlternationCount="2" MaxItemsResults="8"                           
                            SelectedValue="{Binding NewMember, UpdateSourceTrigger=PropertyChanged}"                            
                            MaxDropDownHeight="800"                                                
                            IsEditable="True" ContainsFilter="true"
                            RefreshItemSource="{Binding RefreshMemberFilter}"
                            CustomFilter="{Binding MemberCustomFilter}"
                            ItemTemplate="{StaticResource MemberDataTemplate}"
                            ItemsSource="{Binding Members}"/>

                            <Menu>
                                <MenuItem                             
                                x:Name="addMemberMenuItem"
                                Header="{x:Static props:Resources.Add_member}" ItemsSource="{Binding Roles}" Command="{Binding ElementName=thisView, Path=DataContext.AddNewMemberCommand}">
                                    <MenuItem.ItemContainerStyle>
                                        <Style TargetType="MenuItem">
                                            <Setter Property="Template" Value="{StaticResource ToolBarMenu_SubmenuItem}"/>
                                            <Setter Property="Command" Value="{Binding ElementName=thisView, Path=Model.AddNewMemberCommand}"/>
                                            <Setter Property="CommandParameter" Value="{Binding Role}"/>
                                        </Style>
                                    </MenuItem.ItemContainerStyle>
                                    <MenuItem.Icon>
                                        <Image Source="/Images/ToolBar/Add.png" Width="32" Height="32" Stretch="Uniform"/>
                                    </MenuItem.Icon>

                                    <MenuItem.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                                                <Image Source="/Images/ToolBar/TeamMember.png" Width="16" Height="16" Stretch="Uniform" Margin="0,0,5,0"/>
                                                <TextBlock Foreground="{StaticResource ToolBarMenuForegroundBrush}" Text="{Binding Role.RoleName}" VerticalAlignment="Center" />
                                            </StackPanel>
                                        </DataTemplate>
                                    </MenuItem.ItemTemplate>
                                </MenuItem>
                            </Menu>
                        </StackPanel>
                        <Border.Style>
                            <Style BasedOn="{StaticResource ToolBarInsideBorder}" TargetType="{x:Type Border}">
                                <Setter Property="Border.Visibility" Value="Collapsed"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsAddMemberVisible}" Value="true">
                                        <Setter Property="Border.Visibility" Value="Visible"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Border.Style>
                    </Border>

                    <Menu Grid.Column="1">
                        <MenuItem  Header="{x:Static props:Resources.Join}" Command="{Binding ShowJoinDialogCommand}"
                              Style="{StaticResource Toolbar_MenuItemStyleHideWhenDisabled}">
                            <MenuItem.Icon>
                                <Image Source="/Images/ToolBar/joinProject.png" Width="32" Height="32" Stretch="Uniform"/>
                            </MenuItem.Icon>
                        </MenuItem>


                        <MenuItem Header="{x:Static props:Resources.Roles}" Command="{Binding ShowRolesListCommand}"
                              Style="{StaticResource Toolbar_MenuItemStyleHideWhenDisabled}">
                            <MenuItem.Icon>
                                <Image Source="/Images/ToolBar/editRoles.png" Width="32" Height="32" Stretch="Uniform"/>
                            </MenuItem.Icon>
                        </MenuItem>

                        <MenuItem Header="{x:Static props:Resources.Contacts}" Command="{Binding ShowContactListCommand}">
                            <MenuItem.Icon>
                                <Image Source="/Images/ToolBar/Contact_Book.png" Width="32" Height="32" Stretch="Uniform"/>
                            </MenuItem.Icon>
                        </MenuItem>
                    </Menu>
                    
                    
                    

                </Grid>

            </ToolBar>
        </SF_Helpers:PanelLayout.Toolbar>

        <!-- CONTENT -->
        <SF_Helpers:PanelLayout.Content>
            <ListBox            
            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            HorizontalAlignment="Stretch"
            Background="Transparent"            
            BorderThickness="0"            
            ItemContainerStyle="{StaticResource NoSelectionListBoxItem}"
            ItemsSource="{Binding GroupedProjectMemberships}">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel Orientation="Horizontal"  />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <TextBlock
                                Margin="0,5,0,5"
                                Style="{StaticResource GroupTextBlock}"
                                Text="{Binding Path=Name, StringFormat='{}{0}(s)'}"/>
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                    </GroupStyle>
                </ListBox.GroupStyle>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="0,0,10,10">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>                                
                                <ColumnDefinition Width="230"/>                                
                            </Grid.ColumnDefinitions>

                            <ContentControl
                                Grid.Column="0"
                                Margin="5,0,10,0"
                                DataContext="{Binding Member}"
                                HorizontalAlignment="Center" VerticalAlignment="Top"
                                Style="{StaticResource MemberImageControlStyle}"/>

                            <StackPanel Grid.Column="1">
                                <StackPanel Orientation="Horizontal">

                                    <TextBlock
                                        Style="{StaticResource ItemTitleTextBlock}" VerticalAlignment="Center" MaxWidth="200" Margin="0,0,5,0"                              
                                        Text="{Binding Member.FullName}" TextTrimming="CharacterEllipsis" TextWrapping="NoWrap"/>

                                    <ComboBox                                                                                                                                                                                
                                        SF_Comp:CommandBehavior.RoutedEventName="SelectionChanged"  VerticalAlignment="Center" 
                                        SF_Comp:CommandBehavior.TheCommandToRun="{Binding ChangeDayAllocationCommand}"
                                        SelectedValue="{Binding ProjectMembership.DayAllocation}">
                                        <ComboBox.Style>
                                            <Style TargetType="ComboBox" BasedOn="{StaticResource MemberAllocationComboBox}">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding UserCanChangeAllocation}" Value="False">
                                                        <Setter Property="Background" Value="Transparent"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </ComboBox.Style>
                                    </ComboBox>
                                    

                                </StackPanel>

                                <TextBlock Text="{Binding Member.CompanyName}"  TextTrimming="CharacterEllipsis"/>
                                <TextBlock>                                
                                    <Hyperlink
                                            NavigateUri="{Binding Member.EmailAccount}"
                                            SF_Comp:CommandBehavior.RoutedEventName="RequestNavigate"
                                            SF_Comp:CommandBehavior.TheCommandToRun="{Binding SendEmailCommand}">
                                        <TextBlock Text="{Binding Member.EmailAccount}" FontSize="{StaticResource SmallFontSize}" TextTrimming="CharacterEllipsis"/>    
                                    </Hyperlink>                                    
                                </TextBlock>
                                <TextBlock Text="{x:Static props:Resources.not_engaged}"
                                           Background="{StaticResource AlertBackgroundBrush}" Foreground="{StaticResource AlertBrush}"
                                           FontSize="{StaticResource SmallFontSize}">
                                    <TextBlock.Style>
                                        <Style>
                                            <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding ProjectMembership.DayAllocation}" Value="{x:Null}">
                                                    <Setter Property="TextBlock.Visibility" Value="Visible"/>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </TextBlock.Style>
                                </TextBlock>
                                
                                
                                
                                                                
                            </StackPanel>

                            <DockPanel Grid.Column="1" Style="{StaticResource ItemActionMenu}">
                                <Button                                                           
                                    Style="{StaticResource RemoveActionButton}"
                                    Command="{Binding ElementName=thisView, Path=DataContext.RemoveMemberCommand}"
                                    CommandParameter="{Binding .}"/>
                            </DockPanel>

                            

                           
                        </Grid>

                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </SF_Helpers:PanelLayout.Content>

    </SF_Helpers:PanelLayout>

</UserControl>
